
const app = getApp()
Page({
  data: {
    code:null,
    openid:null,
  },
  ondenglu(e){
   let  that = this
   var getopenid = wx.getStorageSync('openid')
   if(getopenid){
    wx.navigateTo({
      url: '../mypassword/mypassword?openid='+getopenid,
    })
   }else{
    wx.login({
      success (res) {
          console.log(res)
         let codes = res.code
          wx.request({
            url: 'https://wxtp.hephp.cn/Api/Login/getcode', //仅为示例，并非真实的接口地址
            data: {
              code: codes,
            },
            header: {
              'content-type': 'application/json' // 默认值
            },
            success (e) {
              console.log(e)
                if(e.data.openid!=null){
                    let openid = e.data.openid
                    that.setData({
                      openid:openid
                    })
                    wx.setStorageSync('openid', openid)
                    wx.navigateTo({
                      url: '../mypassword/mypassword?openid='+openid,
                    })
                }else{
                  wx.showToast({
                    title: '请重新授权登录',
                    icon: 'error',
                    duration: 2000
                  })
                }
            }
          })
      }
    })
  }
  },
  onLoad(e){
    var getopenid = wx.getStorageSync('openid')
    if(getopenid){
     wx.navigateTo({
       url: '../mypassword/mypassword?openid='+getopenid,
     })
    }
  }
})
